#include <iostream>
#include <string>
#include <cstdlib>

#include "error.h"

using namespace std;

void errorMessage(ErrorNum err, const string& var, int nLine)
{
    switch (err)
    {
        case ERR_FILE_LOAD:
            cerr<<"ERROR: "<<ERR_FILE_LOAD<<" :: Unable to load the source file "<<var<< \
                ", make sure it exists\n";
            exit(ERR_FILE_LOAD);
            break;

        case ERR_UNKNOWN:
            cerr<<"ERROR: "<<ERR_UNKNOWN<<" :: In line "<<nLine+1<<": WTF just happened ?! I have no idea!\n";
            exit(ERR_UNKNOWN);
            break;

        case ERR_INVALID_NUMBER:
            cerr<<"ERROR: "<<ERR_INVALID_NUMBER<<" :: In line "<<nLine+1<<": The number \'"<<var<<"...\' entered was invalid.\n";
            exit(ERR_INVALID_NUMBER);
            break;

        case ERR_UNKOWN_TOKEN:
            cerr<<"ERROR: "<<ERR_UNKOWN_TOKEN<<" :: In line "<<nLine+1<<": The token \'"<<var<<"\' is possibly misplaced.\n";
            exit(ERR_UNKOWN_TOKEN);
            break;

        case ERR_INVALID_KEYWORD:
            cerr<<"ERROR: "<<ERR_INVALID_KEYWORD<<" :: In line "<<nLine+1<<": \'"<<var<<"\' is not a valid keyword.\n";
            exit(ERR_INVALID_KEYWORD);
            break;

        case ERR_EXPECTED_SYMBOL:
            cerr<<"ERROR: "<<ERR_EXPECTED_SYMBOL<<" :: In line "<<nLine+1<<": Expected symbol \'"<<var<<"\'.\n";
            exit(ERR_EXPECTED_SYMBOL);
            break;

        case ERR_INVALID_VARTYPE:
            cerr<<"ERROR: "<<ERR_INVALID_VARTYPE<<" :: In line "<<nLine+1<<": Invalid variable type \'"<<var<<"\'.\n";
            exit(ERR_INVALID_VARTYPE);
            break;

        case ERR_EXPECTED_EOSS:
            cerr<<"ERROR: "<<ERR_EXPECTED_EOSS<<" :: In line "<<nLine+1<<": Expected \';\' after token \'"<<var<<"\'.\n";
            exit(ERR_EXPECTED_EOSS);
            break;

        case ERR_INVALID_TOKEN_COUNT:
            cerr<<"ERROR: "<<ERR_INVALID_TOKEN_COUNT<<" :: In line "<<nLine+1<<": Check the syntax of the statement.\n";
            exit(ERR_INVALID_TOKEN_COUNT);
            break;

        case ERR_DUP_IDENTIFIER:
            cerr<<"ERROR: "<<ERR_DUP_IDENTIFIER<<" :: In line "<<nLine+1<<": The identifier \'"<<var<< \
                    "\' already exists, use another name.\n";
            exit(ERR_DUP_IDENTIFIER);
            break;

        case ERR_INVALID_IDENT:
            cerr<<"ERROR: "<<ERR_INVALID_IDENT<<" :: In line "<<nLine+1<<": The identifier \'"<<var<<"\' does not exist.\n";
            exit(ERR_INVALID_IDENT);
            break;

        case ERR_CUSTOM:
            cerr<<"ERROR: "<<ERR_CUSTOM<<" :: In line "<<nLine+1<<": "<<var<<"\n";
            exit(ERR_CUSTOM);
            break;

        case ERR_IDENT_MISMATCH:
            cerr<<"ERROR: "<<ERR_IDENT_MISMATCH<<" :: In line "<<nLine+1<<": Variable type mismatch.\n";
            exit(ERR_IDENT_MISMATCH);
            break;

        case ERR_IDENT_UNINIT:
            cerr<<"ERROR: "<<ERR_IDENT_UNINIT<<" :: In line "<<nLine+1<<": Variable \'"<<var<<"\' was left uninitialized.\n";
            exit(ERR_IDENT_UNINIT);
            break;

        case ERR_EXPECTED_EXPR:
            cerr<<"ERROR: "<<ERR_EXPECTED_EXPR<<" :: In line "<<nLine+1<<": Expected expression.\n";
            exit(ERR_EXPECTED_EXPR);
            break;

        case ERR_EXPECTED_IDENT:
            cerr<<"ERROR: "<<ERR_EXPECTED_IDENT<<" :: In line "<<nLine+1<<": Expected identifier.\n";
            exit(ERR_EXPECTED_IDENT);
            break;

        default:
            cerr<<"This error was not assigned a number.\n";
            break;
    }
}
